<template>
	<view>
		<nav-back></nav-back>

		<view class="title">
			<text>{{currentMenu}}</text>
		</view>
		<view class="tip">最真实的自己，更快遇到最应该的那个人</view>

		<picker-view  @change="changeCareer" :value="careerValue" class="my-picker-view">
			<picker-view-column>
				<view class="item" v-for="(item,index) in currentNameList" :key="index">{{item}}</view>
			</picker-view-column>
		</picker-view>

		<button class="next" type="primary" @click="handleNext">下一步</button>
	</view>
</template>

<script>
	import request from '@/utils/request.js'
	import NavBack from '@/components/NavBack.vue'
	import careerList from '@/utils/career.js'

	export default {
		components: {
			NavBack
		},
		data() {
			return {
				careerList: [],
				currentCareerList: [],
				currentNameList: [],
				currentCareerObject: {},
				currentMenu: '您的职业',
				careerValue: [1],
			}
		},
		onLoad() {
			this.careerList = careerList
			this.currentNameList=this.careerList.map(item => {
					return item.name
				}),
			this.currentCareerList=this.careerList,
			this.currentCareerObject=this.careerList[2]
		},
		methods: {
			changeCareer(event) {
				// console.log(event.detail.value, 'changecareer');
				let index = event.detail.value[0]
				this.currentCareerObject=this.currentCareerList[index]
				this.careerValue[0] = index
			},
			handleNext() {
				console.log(this.currentCareerObject, 'currentCareerObject');
				if (this.currentCareerObject.children) {
					this.currentNameList = this.currentCareerObject.children.map(item => {
						return item.name
					}),
					this.currentCareerList = this.currentCareerObject.children,
					this.currentCareerObject = this.currentCareerObject.children[0],
					this.currentMenu = this.currentCareerObject.name
					return
				} else {
					getApp().globalData.userInfo.profession = this.currentCareerObject.name
					console.log(getApp().globalData.userInfo.profession, 'profession');
					uni.redirectTo({
						url: '/pages/userInfo/carInfo/carInfo'
					})
				}
			},
		}
	}
</script>


<style lang="scss">
	@import "@/style/register.scss";
</style>